Extracting the mean profile is based on the really nice paper by Chu et al (2010).

## Loading required package: tools
## Loading required package: XML
## 
## Attaching package: 'XML'
## The following object is masked from 'package:tools':
## 
##     toHTML
## Loading required package: rgl
## Loading required package: shiny
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

## Saving 7 x 5 in image

## Saving 7 x 5 in image

## 
## Call:
## lm(formula = twist ~ x, data = subset(dframe, between(x, 220, 
##     600)))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.0459 -1.1544 -0.1613  0.8461  9.4853 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 803.959580   0.465478  1727.2   <2e-16 ***
## x            -0.127593   0.001096  -116.4   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.884 on 242 degrees of freedom
## Multiple R-squared:  0.9825, Adjusted R-squared:  0.9824 
## F-statistic: 1.355e+04 on 1 and 242 DF,  p-value: < 2.2e-16

## Saving 7 x 5 in image

## Saving 7 x 5 in image

in black: average of all, in blue average based on profiles below 500, in green average based on profiles below 300, in red profile at 100.